<template>
  <el-dialog
    :visible.sync="integralVisible"
    width="30%"
    append-to-body
    :title="this.val == 1 ? '部门导出' : '个人导出'"
    :before-close="close"
  >
    <el-form>
      <el-form-item>
        <el-checkbox :indeterminate="isIndeterminate" v-model="checkAll" @change="handleCheckAllChange">全选</el-checkbox>
      </el-form-item>
      <el-form-item>
        <!--        <el-checkbox-group v-model="type">-->
        <!--                    <el-checkbox v-for="i in optionuser" :label="i" :key="i.name" @change="change(i)">{{i.name}}</el-checkbox>-->
        <!--        </el-checkbox-group>-->
        <span><el-checkbox v-model="rank">名次</el-checkbox>
        <el-checkbox v-if="this.val == 2" v-model="realnameStr">姓名</el-checkbox>
        <el-checkbox v-model="deptName">部门</el-checkbox>
         <el-checkbox v-model="loginGrade">登录</el-checkbox>
        <el-checkbox v-model="newsGrade">新闻</el-checkbox>
        </span><br/>
        <span>
          <el-checkbox v-model="trainSelfGrade">课程</el-checkbox>
          <el-checkbox v-model="trainImgGrade">图片</el-checkbox>
          <el-checkbox v-model="trainVedioGrade">视频</el-checkbox>
          <el-checkbox v-model="trainFileGrade">文件</el-checkbox>
          <el-checkbox v-model="trainExamGrade">考试</el-checkbox>
        </span><br/>
        <span>
        <el-checkbox v-model="trainGrade">课程总分</el-checkbox>
        <el-checkbox v-model="oneQuesGrade">每日一题</el-checkbox>
        <el-checkbox v-model="modelGrade">模拟考试</el-checkbox>
        <el-checkbox v-model="normalGrade">正式考试</el-checkbox>
        </span><br/>
        <span>
           <el-checkbox v-model="deptSumGrade">总积分</el-checkbox>
          <el-checkbox v-if="this.val !== 2" v-model="deptAvgGrade">平均分</el-checkbox>
           <el-checkbox v-model="noticeGrade">公告</el-checkbox>
           <el-checkbox v-if="this.val !== 2" v-model="deptCount">部门人数</el-checkbox>
        </span><br/>

      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="close">取 消</el-button>
      <el-button type="primary" @click="handleDownload()" :loading="loading">确定</el-button>
    </div>
  </el-dialog>
</template>

<script>
  export default {
    name: 'exportintegral',
    data() {
      return {
        loading: false,
        checkAll: false,
        val: '',
        deptName: false,
        deptCount: false,
        deptSumGrade: false,
        deptAvgGrade: false,
        loginGrade: false,
        newsGrade: false,
        noticeGrade: false,
        oneQuesGrade: false,
        modelGrade: false,
        normalGrade: false,
        trainGrade: false,
        trainImgGrade: false,
        trainVedioGrade: false,
        trainFileGrade: false,
        trainExamGrade: false,
        trainSelfGrade: false,
        realnameStr: true,
        rank: true,
        dataForm: {
          deptId: '',
          startTime: []
        },
        type: [],
        tenantId: this.$cookie.get('tenantId'),
        option: {
          ranking: {name: '名次', check: false},
          deep: {name: '部门', deptName: true},
          deepnum: {name: '部门人数', deptCount: false},
          totalscore: {name: '总积分', deptSumGrade: false},
          average: {name: '平均分', deptAvgGrade: false},
          login: {name: '登录', loginGrade: false},
          new: {name: '新闻', newsGrade: false},
          notic: {name: '公告', noticeGrade: false},
          onequelst: {name: '每日一题', oneQuesGrade: false},
          mexam: {name: '模拟考试', modelGrade: false},
          zexam: {name: '正式考试', normalGrade: false},
          course: {name: '课程', trainGrade: false}
        },
        optionuser: {
          ranking: {name: '名次', check: false, labName: 'index + 1'},
          planeName: {name: '姓名', check: false, labName: 'realname'},
          deep: {name: '部门', check: false, labName: 'deptName'},
          totalscore: {name: '总积分', check: false, labName: 'deptSumGrade'},
          login: {name: '登录', check: false, labName: 'loginGrade'},
          new: {name: '新闻', check: false, labName: 'newsGrade'},
          notic: {name: '公告', check: false, labName: 'noticeGrade'},
          onequelst: {name: '每日一题', check: false, labName: 'oneQuesGrade'},
          mexam: {name: '模拟考试', check: false, labName: 'modelGrade'},
          zexam: {name: '正式考试', check: false, labName: 'normalGrade'},
          course: {name: '课程', check: false, labName: 'trainGrade'}
        },
        integralVisible: false,
        isIndeterminate: true
      }
    },
    methods: {
      handleCheckAllChange(val) {
        if (val === true) {
          // eslint-disable-next-line no-unused-expressions,no-sequences
          this.deptCount = true,
            this.deptSumGrade = true,
            this.deptName = true,
            this.deptAvgGrade = true,
            this.realnameStr = true,
            this.loginGrade = true,
            this.newsGrade = true,
            this.noticeGrade = true,
            this.oneQuesGrade = true,
            this.modelGrade = true,
            this.normalGrade = true,
            this.realname = true,
            this.trainGrade = true,
            this.trainImgGrade = true,
            this.trainVedioGrade = true,
            this.trainFileGrade = true,
            this.trainExamGrade = true,
            this.trainSelfGrade = true,
            this.rank = true
        } else {
          // eslint-disable-next-line no-unused-expressions,no-sequences
          this.deptCount = false,
            this.deptSumGrade = false,
            this.deptName = false,
            this.realnameStr = true,
            this.deptAvgGrade = false,
            this.loginGrade = false,
            this.newsGrade = false,
            this.noticeGrade = false,
            this.oneQuesGrade = false,
            this.modelGrade = false,
            this.normalGrade = false,
            this.trainGrade = false,
            this.realname = false,
            this.trainImgGrade = false,
            this.trainVedioGrade = false,
            this.trainFileGrade = false,
            this.trainExamGrade = false,
            this.trainSelfGrade = false,
            this.rank = true
        }
      },
      init(dataForm, val) {
        this.loading = false
        this.dataForm = dataForm
        // eslint-disable-next-line no-sequences,no-unused-expressions
        this.deptCount = false,
          this.deptSumGrade = false,
          this.deptName = false,
          this.deptAvgGrade = false,
          this.loginGrade = false,
          this.newsGrade = false,
          this.noticeGrade = false,
          this.oneQuesGrade = false,
          this.modelGrade = false,
          this.normalGrade = false,
          this.trainGrade = false,
          this.realname = false,
          this.trainImgGrade = false,
          this.trainVedioGrade = false,
          this.trainFileGrade = false,
          this.trainExamGrade = false,
          this.trainSelfGrade = false,
          this.rank = true
        this.val = val
        this.integralVisible = true
      },
      close() {
        this.integralVisible = false
      },
      // change(val) {
      //   val.check = !val.check
      //   this.optionuser.check = val.check
      // },
      handleDownload() {
        this.loading = true
        if (this.val === 1) {
          window.location = this.$http.downloadUrl(
            '/integral-admin/integral/sta/deptExport',
            // `/integral-admin/integral/sta/${this.val === 1 ? 'deptExport' : 'userExport'}`,
            {
              tenantId: this.tenantId,
              deptId: this.dataForm.deptId,
              startTime: this.dataForm.startTime,
              endTime: this.dataForm.endTime,
              deptCount: this.deptCount,
              deptAvgGrade: this.deptAvgGrade,
              deptSumGrade: this.deptSumGrade,
              deptName: this.deptName,
              rank: this.rank,
              loginGrade: this.loginGrade,
              newsGrade: this.newsGrade,
              noticeGrade: this.noticeGrade,
              oneQuesGrade: this.oneQuesGrade,
              modelGrade: this.modelGrade,
              normalGrade: this.normalGrade,
              trainGrade: this.trainGrade,
              trainImgGrade: this.trainImgGrade,
              trainVedioGrade: this.trainVedioGrade,
              trainFileGrade: this.trainFileGrade,
              trainExamGrade: this.trainExamGrade,
              trainSelfGrade: this.trainSelfGrade
            },
            this.integralVisible = false
          )
        } else {
          window.location = this.$http.downloadUrl(
            '/integral-admin/integral/sta/userExport',
            {
              tenantId: this.tenantId,
              realname: this.dataForm.realname,
              deptId: this.dataForm.deptId,
              startTime: this.dataForm.startTime,
              endTime: this.dataForm.endTime,
              realnameStr: this.realnameStr,
              deptSumGrade: this.deptSumGrade,
              deptName: this.deptName,
              rank: this.rank,
              loginGrade: this.loginGrade,
              newsGrade: this.newsGrade,
              noticeGrade: this.noticeGrade,
              oneQuesGrade: this.oneQuesGrade,
              modelGrade: this.modelGrade,
              normalGrade: this.normalGrade,
              trainGrade: this.trainGrade,
              trainImgGrade: this.trainImgGrade,
              trainVedioGrade: this.trainVedioGrade,
              trainFileGrade: this.trainFileGrade,
              trainExamGrade: this.trainExamGrade,
              trainSelfGrade: this.trainSelfGrade
            },
            this.integralVisible = false
          )
        }
      }
    }
  }
</script>

<style scoped>

</style>












